function printCanvas(el)  
{
  var content=el.innerHTML ;
  var pwin=window.open('','print_content','width=100,height=100');

  pwin.document.open();
  pwin.document.write('<html><body onload="window.print()">'+content+'</body></html>');
  pwin.document.close();
 
  setTimeout(function(){pwin.close();},1000);
  
  var start = 'Whitefield, Bangalore, Karnataka, India';    
  var directionsService = new google.maps.DirectionsService();
  var map;
  

  function initialize() {
	  	var rendererOptions = {
		draggable: true
		};
    directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
     var bangalore = new google.maps.LatLng(12.9697612, 77.7508401);
     var myOptions = {
      zoom:12,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: bangalore
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));
 //   alert('initialize') ;
}

function detectLocation() { 
	      // Try W3C Geolocation (Preferred)
	  if(navigator.geolocation) {
	    browserSupportFlag = true;
	    navigator.geolocation.getCurrentPosition(function(position) {
	      	start = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
	      	map.setCenter(start);
	    	}, function() {
	      		handleNoGeolocation(browserSupportFlag);
	    	});
	    document.getElementById("locationmsg").hidden = true ;	
	    }
} 
 
function calcRoute(dest) {
//  alert(dest) ; 
  var request = {
      origin:start, 
      destination:dest,
      travelMode: google.maps.DirectionsTravelMode.DRIVING
  };
  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
    document.getElementById('map_canvas').scrollIntoView() ;
    document.getElementById('gobackto').value = dest ; 
  });
   
}


function computeTotalDistance(result) {
	  var total = 0;
	  var myroute = result.routes[0];
	  for (i = 0; i < myroute.legs.length; i++) {
	    total += myroute.legs[i].distance.value;
	  }
	  total = total / 1000.
	  document.getElementById("total").innerHTML = total + " km";
	}
	
	
 function goback()  {
 	var gobackto  = document.getElementById('gobackto').value ;
 	document.getElementById(gobackto).scrollIntoView() ;
 }
 
	 var _gaq = _gaq || [];
	 _gaq.push(['_setAccount', 'UA-28008925-1']);
	 _gaq.push(['_trackPageview']);
		
	 (function() {
	   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	 })(); 
}